<template>
  <el-container :style="{ height: screenHeight }">
    <el-aside width="200px">

      <el-menu default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose">

        <el-submenu v-for="(item, index) in menuList" :key="index" :index="index">
          <template slot="title">
            <i class="el-icon-location"></i>
            <span>{{ item.name }}</span>
          </template>

          <el-menu-item v-for="(subitem, subindex) in item.children" :key="subindex" ><router-link :to="subitem.href" tag="span">{{ subitem.name
          }}</router-link></el-menu-item>

        </el-submenu>
      </el-menu>
      <el-button type="danger" round @click="logout">退出登录</el-button>
    </el-aside>
    <el-container>

      <el-header>金融借贷项目后台管理</el-header>
      <el-main><router-view></router-view></el-main>

    </el-container>
  </el-container>
</template>

<script>
import Vue from 'vue'
export default {
  
  data() {
    return {
      screenHeight: document.documentElement.clientHeight + "px",
      menuList:[],
      a:"",
    };
  },
  methods: {
    logout() {
      this.$confirm("退出登录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //请求路径默认为/logout
          this.$axios.delete("logout").then((res) => {
            if (res.data.code == 200) {
              //清空localStorage对应的信息
              sessionStorage.setItem("authorization", "");
              this.$message.success(res.data.message);
              //跳转到登录页面
              this.$router.push("/");
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        }); this.$confirm("退出登录, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            //请求路径默认为/logout
            this.$axios.delete("logout").then((res) => {
              if (res.data.code == 200) {
                //清空localStorage对应的信息
                sessionStorage.setItem("authorization", "");
                this.$message.success(res.data.message);
                //跳转到登录页面
                this.$router.push("/");
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消",
            });
          });
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
  mounted() {
    Vue.nextTick();
    this.menuList = JSON.parse(sessionStorage.getItem("list"));
   
    
  }
};
</script>
<style>
.el-header {
  background-color: #ffffff;
  color: rgb(100, 100, 100);

  text-align: center;
  line-height: 60px;
  height: auto;
}

.el-aside {
  background-color: #ffffff;
  color: rgb(255, 252, 252);
  text-align: center;
  line-height: 200px;
  height: auto;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  /* line-height: 160px; */
  height: auto;
}

body>.el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
  height: auto;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
  height: auto;
}
</style>